package org.eclipseuseradmin.ui.model;

import org.eclipseuseradmin.ui.IRoleElement;
import org.eclipseuseradmin.ui.IUser;
import org.osgi.service.useradmin.UserAdmin;

public class UserModel extends RoleElementModel {

	protected String password;
	
	protected String confirmPassword;

	public UserModel(UserAdmin userAdmin) {
		super(userAdmin);
	}

	public UserModel(UserAdmin userAdmin, IUser user) {
		super(userAdmin, user);
	}

	@Override
	public void save() {

		super.save();
		if (password != null) {
			getUser().setPassword(password);
			password = null;
		}
	}

	public void changePassword(String password) {
		
		getUser().setPassword(password);
	}
	
	@Override
	public IRoleElement create() {
		
		return null;
	}

	public String getPassword() {

		if (password != null) {
			return password;
		}
		if (roleElement != null) {
			return getUser().getPassword();
		}
		return null;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	private IUser getUser() {
		return (IUser) roleElement;
	}

	public String getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

}
